import "./index.less";
import Toolbar from "@/components/ViewComponents/Toolbar";
import { useTranslation } from "react-i18next";
import { BasicTable, useTable, BasicColumn } from "@/components/Table";
import { del_emergencies } from "@/api/EmergencyDictionary";
import TableAction from "@/components/Table/components/TableAction";
import DetailDrawer_AddUpdate from "./components/DrawerAddUpdate";
import { useDrawer } from "@/components/Drawer";
import { useState } from "react";
import { IconEnum } from "@/enums/appEnum";
export default function emergency_medical_records() {
	const { t } = useTranslation();
	let [getTitle, setGetTitle] = useState("");
	let btnList = [
		"add"
		//  "edit", "save", "print", "end"
	];
	// 配置table
	const columns: BasicColumn[] = [
		{
			title: t("felix_ui.sq_numb"),
			width: 100,
			// dataIndex: "sq_numb",
			render: (text, record, index) => index * 1 + 1 // 设置序号
		},
		{
			title: t("felix_ui.time"),
			dataIndex: "time"
		},
		{
			title: t("felix_ui.department"),
			dataIndex: "department"
		},
		{
			title: t("felix_ui.dt_date"),
			dataIndex: "dt_date"
		},
		{
			title: t("felix_ui.beneficiary"),
			dataIndex: "beneficiary"
		},
		{
			title: t("felix_ui.reg_content"),
			dataIndex: "reg_content"
			// render: text => <span>{TimeDate(text)}</span>
		},
		{
			title: t("felix_ui.amount"),
			dataIndex: "amount"
			// render: text => <span>{TimeDate(text)}</span>
		},
		{
			title: t("felix_ui.operate"),
			key: "action",
			fixed: "right",
			width: 200,
			render: (_, record: any) => (
				<TableAction
					actions={[
						{
							icon: IconEnum.EDIT,
							label: t("felix_ui.edit"),
							onClick: handleEdit.bind(null, record)
						},
						{
							icon: IconEnum.DELETE,
							label: t("felix_ui.delete"),
							popConfirm: {
								title: t("common.deleteMessage"),
								placement: "left",
								confirm: handleDel.bind(null, record)
							}
						}
					]}
				></TableAction>
			)
		}
	];
	let getArrList = () => {
		return [
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			},
			{
				time: "2024-12-05",
				department: "adsfghj",
				dt_date: "2024-12-05",
				beneficiary: "adsfgdas",
				reg_content: "879546465",
				amount: "fgdhfhgfdssa"
			}
		];
	};
	// 顶部查询
	let searchFormSchema = () => {
		return [
			{
				label: t("felix_ui.patient_ID"),
				field: "patientId",
				component: "Input",
				colProps: { span: 8 }
			},
			{
				label: t("felix_ui.full_name"),
				field: "fullName",
				component: "Input",
				colProps: { span: 8 }
			},
			{
				label: t("felix_ui.department"),
				field: "department",
				component: "Input",
				colProps: { span: 8 }
			},
			{
				label: t("felix_ui.pat_cardno"),
				field: "pat_cardno",
				component: "Input",
				colProps: { span: 8 }
			}
		];
	};
	// 配置table
	const [registerTable, { reload }] = useTable({
		// api: get_selectEmergen,
		dataSource: getArrList(),
		columns,
		formConfig: {
			labelWidth: 120,
			schemas: searchFormSchema(),
			showActionButtonGroup: true,
			showAdvancedButton: false
		},
		bordered: true,
		useSearchForm: true
	});
	const [drawer_add_update, { openDrawer: opendDrawer_add_update }] = useDrawer();
	// 修改
	const handleEdit = async (record: Recordable) => {
		setGetTitle(t("felix_ui.edit_emergency_info"));
		opendDrawer_add_update(true, {
			record
		});
	};
	// 删除
	const handleDel = async (record: Recordable) => {
		console.log(record);
		await del_emergencies(record.emgId).then(() => {
			reload();
		});
	};
	// 新增
	const handleAdd = () => {
		setGetTitle(t("felix_ui.add_emergency_info"));
		opendDrawer_add_update(true, {});
	};
	const handleSubmitRegistration = async () => {
		// try {
		// 	const values1 = await validateFields();
		// 	console.log("提交Form", values1);
		// 	await create_emergencies(values1);
		// } catch (err) {
		// 	console.log(err);
		// }
	};
	const handlerToolbarAction = (key: string) => {
		switch (key) {
			case "save":
				handleSubmitRegistration();
				break;
			case "add":
				handleAdd();
				break;
		}
		console.log("key", key);
	};
	return (
		<div className="emergency_medical_records page">
			<div className="emergency_medical_records_content">
				<BasicTable register={registerTable}></BasicTable>
				<DetailDrawer_AddUpdate getTitle={getTitle} reload={reload} register={drawer_add_update}></DetailDrawer_AddUpdate>
			</div>
			<Toolbar action={handlerToolbarAction} btnList={btnList} />
		</div>
	);
}
